package onlyfun.caterpillar;
    import java.sql.Connection;
    import java.sql.SQLException;
    public interface DBSource {
    public Connection getConnection() throws SQLException;
    public void closeConnection(Connection conn) throws SQLException;
    }
        public class SimpleDBSourceimplementsDBSource {
            鈥??
                public SimpleDBSource(String configFile) throws IOException,
                        ClassNotFoundException {
                    props = new Properties();
                    props.load(new FileInputStream(configFile));
                    url = props.getProperty("onlyfun.caterpillar.url");
                    user = props.getProperty("onlyfun.caterpillar.user");
                    passwd = props.getProperty("onlyfun.caterpillar.password");
                    Class.forName(
                            props.getProperty("onlyfun.caterpillar.driver"));
                }
                public Connection getConnection() throws SQLException {
                    return DriverManager.getConnection(url, user, passwd);
                }
                public void closeConnection(Connection conn) throws SQLException {
        c           onn.close();
                }
        }
     onlyfun.caterpillar.driver=com.mysql.jdbc.Driver
        onlyfun.caterpillar.url=jdbc:mysql://localhost:3306/demo
        onlyfun.caterpillar.user=root
        onlyfun.caterpillar.password=123456

                
                DBSource dbsource = new SimpleDBSource();
            Connection conn = dbsource.getConnection();
            
            if(!conn.isClosed()) {
                System.out.println("鏁版嵁搴撹繛鎺ュ凡寮??鍚????");
            }
            
            dbsource.closeConnection(conn);
            
            if(conn.isClosed()) {
                System.out.println("鏁版嵁搴撹繛鎺ュ凡鍏抽棴â??");
            }

